package com.yc.sole.framework.web;

import com.google.common.collect.Lists;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collection;
import java.util.Collections;

/**
 * @author yizuomin
 * @date 2022/11/19 16:33
 **/
@Slf4j
@Configuration
public class DefaultSecurityConfig {

    @Bean
    @ConditionalOnMissingBean(SecurityAuthenticator.class)
    public SecurityAuthenticator securityAuthentication() {
        log.warn("未实现SecurityAuthentication，使用默认配置！");
        return new SecurityAuthenticator() {
            @Override
            public BaseUserInfo getUserInfo(String token) {
                return new BaseUserInfo() {
                    @Override
                    public Long getId() {
                        return null;
                    }

                    @Override
                    public String getUsername() {
                        return null;
                    }

                    @Override
                    public Collection<Long> getRoleIds() {
                        return Collections.emptyList();
                    }

                    @Override
                    public Collection<String> getPermissions() {
                        return Collections.emptyList();
                    }
                };
            }

            @Override
            public void login(String token, Object value) {
                throw new UnsupportedOperationException();
            }

            @Override
            public void logout(String token) {
                throw new UnsupportedOperationException();
            }

            @Override
            public void logout(HttpServletRequest request) {
                throw new UnsupportedOperationException();
            }

            @Override
            public Collection<String> getWhiteList() {
                return Lists.newArrayList("/**");
            }

            @Override
            public boolean enableAuthentication() {
                return false;
            }
        };
    }
}
